package com.ouman.luoliluoli.adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.ouman.luoliluoli.R;
import com.ouman.luoliluoli.models.SponsorModel;

import java.util.List;

/**
 * Created by jintian on 13/05/2017.
 */

public class SponsorRecyclerViewAdapter extends RecyclerView.Adapter<SponsorRecyclerViewAdapter.ViewHolder> {


    private Context context;
    private List<SponsorModel> data;
    public SponsorRecyclerViewAdapter(Context context, List<SponsorModel> data){
        this.context = context;
        this.data = data;
    }

    public SponsorRecyclerViewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType){
        View view = LayoutInflater.from(context).inflate(R.layout.recyclerview_item_sponsor, null);

        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                System.out.println("===>>click!!!!!");
            }
        });

        return new SponsorRecyclerViewAdapter.ViewHolder(view);
    }

    public void onBindViewHolder(final SponsorRecyclerViewAdapter.ViewHolder holder, final int position){
        String name = data.get(position).getSponsor_name();
        String word = data.get(position).getSponsor_extra_word();

        holder.textViewInfo.setText(name);
        holder.textViewExtra.setText(word);


    }

    public int getItemCount(){
        return data.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        TextView textViewInfo;
        TextView textViewExtra;
        public ViewHolder(View view){
            super(view);
            textViewInfo = (TextView) view.findViewById(R.id.textViewSponsorInfo);
            textViewExtra = (TextView) view.findViewById(R.id.textViewSponsorExtraWord);
        }

    }
}
